﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_BaiThi_loadBaiLam : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        loadData();
    }
    private void loadData() {
        int MaBaiThi = int.Parse(Request.Params["MaBaiThi"]);
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        BaiThiINFO mBaiThi = BaiThiDAL.getInfo(MaBaiThi);

        List<CauHoiINFO> ds = ChiTietDeThiDAL.listByCauHoi(mBaiThi.MaDe);

        string smacauhoi = "";
        for (int i = 0; i < ds.Count; i++)
        {
            smacauhoi += ds[i].MaCH;
            if (i < ds.Count - 1)
                smacauhoi += ",";
        }

        List<DapAnINFO> dsDA = DapAnDAL.listByCauHoi(smacauhoi);
        List<ChiTietBaiThiINFO> dsBaiLam = ChiTietBaiThiDAL.listAll(mBaiThi.MaBaiThi);
        int STT = 1;
        foreach (var item in ds)
        {
            sb.Append("<div><b>").Append(STT).Append(". ").Append(item.NoiDungCH).Append("</b>");
            sb.Append("<div>");
            ChiTietBaiThiINFO m = dsBaiLam.SingleOrDefault(t => t.MaCH == item.MaCH);
            List<string> dsLuaChon = new List<string>();
            if(m != null)
                dsLuaChon = m.DapAnChon.Split(',').ToList<string>();
            string LuaChon = "";
            int j = 65;
            foreach (var item1 in dsDA)
            {
                if (item1.MaCH == item.MaCH) {
                    if (dsLuaChon.IndexOf(item1.MaDA.ToString()) > -1)
                    {
                        sb.Append("<span style='color:#E5231F;'>").Append(Convert.ToChar(j)).Append(".").Append(" ");
                        sb.Append(item1.NoiDungDA).Append("</span>").Append("<br />");
                    }
                    else {
                        sb.Append("<span>").Append(Convert.ToChar(j)).Append(".").Append(" ");
                        sb.Append(item1.NoiDungDA).Append("</span>").Append("<br />");
                    }
                    if (item1.GiaTri == 1)
                        LuaChon += ", " + item1.NoiDungDA;
                    j++;
                }
            }
            if(LuaChon.Length > 1)
            LuaChon = LuaChon.Substring(1);
            sb.Append("<span style='color:#0600FF;'> Đáp án: ").Append(LuaChon).Append("</span>");
            sb.Append("</div></div>");
            sb.Append("<p></p>");
            STT++;
        }
        //sb.Append("<div>").Append("Khái niệm function trong C/C++ trong Java được gọi là:");
        //sb.Append("<div>").Append("<span class='text-warning'>Classes</span>").Append("<br />");
        //sb.Append("<span>Method</span><br />").Append("<span>Object</span><br />");
        //sb.Append("<span>Function</span>").Append("</div></div>");
        //sb.Append("<p></p>");
        ltrContent.Text = sb.ToString();
    }
}